using System.Text;
using System.Windows.Forms;

namespace 软构作业Winform
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                filePath1 = openFileDialog1.FileName;
                //lblFile1.Text = filePath1;
            }
        }

        private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
        {

        }
        //private OpenFileDialog openFileDialog1 = new OpenFileDialog()
        //{
        //    Filter = "文本文件|*.txt",
        //    Multiselect = false
        //};
        private string filePath1, filePath2;

        private void button2_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                filePath2 = openFileDialog1.FileName;
                //lblFile1.Text = filePath1;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                // 创建Data目录
                string dataDir = Path.Combine(Application.StartupPath, "Data");
                if (!Directory.Exists(dataDir))
                {
                    Directory.CreateDirectory(dataDir);
                }

                // 读取文件内容
                string content1 = File.ReadAllText(filePath1, Encoding.UTF8);
                string content2 = File.ReadAllText(filePath2, Encoding.UTF8);

                // 生成新文件路径
                string newFile = Path.Combine(dataDir, $"merged_{DateTime.Now:yyyyMMddHHmmss}.txt");

                // 合并写入
                File.WriteAllText(newFile, content1 + Environment.NewLine + content2, Encoding.UTF8);

                MessageBox.Show($"合并成功！保存路径：{newFile}");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"操作失败：{ex.Message}");
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
